package com.zm.schedule.schedulemgr.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import com.github.pagehelper.Page;
import com.zm.base.core.dao.IBaseDao;
import com.zm.base.core.exception.BaseException;
import com.zm.schedule.schedulemgr.po.TbZmScheduleJob;
import com.zm.schedule.schedulemgr.vo.TbZmScheduleJobVO;


/**
 * @author chenhuaming
 * @Time：2017年5月3日 上午10:40:22
 * @version 1.0
 */
@Repository("scheduleDao")
public interface IScheduleDao extends IBaseDao {
/**
 * 获取任务（分页或者所有）
 * getSchedules:() 
 * @author chenhuaming 
 * @param page
 * @param jobName
 * @param jobGroup
 * @return
 * @throws BaseException
 * @throws Exception
 */
public Page<TbZmScheduleJobVO> getSchedules(Page page,@Param(value="jobName") String jobName,@Param(value="jobGroup") String jobGroup)throws BaseException,Exception;
/**
 * 查询所有任务
 * @author chenhuaming
 * @Time 2017年5月9日
 * @return
 * @throws BaseException
 * @throws Exception
 */
@Select(" select * from tb_zm_schedule_job where STATUS !='1'  ")
public List<TbZmScheduleJob> getAllSchedules()throws BaseException,Exception;
/**
 * 更新任务状态
 * updateJobStatusByJobName:() 
 * @author chenhuaming 
 * @param name
 * @throws BaseException
 * @throws Exception
 */
@Update(" UPDATE `tb_zm_schedule_job` SET STATUS=#{status} WHERE JOB_NAME=#{jobName} ")
public void  updateJobStatusByJobName(@Param(value="status") String status,@Param(value="jobName") String jobName)throws BaseException,Exception;
/**
 * 删除5天前的任务日志
 * delJobLogTwoDayAgo:() 
 * @author chenhuaming
 */
@Delete(" DELETE FROM tb_zm_schedule_job_log WHERE TO_DAYS(NOW())-TO_DAYS(COMPLETE_DATE)>5 ")
public void delJobLogFiveDayAgo()throws BaseException,Exception;
/**
 * 根据job名称和组名 查询job
 * getJobByJobNameAndJobGroup:() 
 * @author chenhuaming 
 * @param jobName
 * @param jobGroup
 * @return
 * @throws BaseException
 * @throws Exception
 */
@Select(" SELECT * FROM tb_zm_schedule_job WHERE JOB_NAME=#{jobName} AND JOB_GROUP=#{jobGroup} ")
public TbZmScheduleJob getJobByJobNameAndJobGroup(@Param(value="jobName")String jobName,@Param(value="jobGroup")String jobGroup)throws BaseException,Exception;
	
}
